<?php
if(!empty($_GET['sms'])){
	$phone = $_GET['phone'];
	$coding = $_GET['coding'];
	set_phone($phone,$coding);
}

// 以下为核心代码部分
function set_phone($phone,$coding){
	// 必要参数
	// $apikey = "90b037a254fdfb6a3912fc64d5012a92";
	$apikey = "cfe9053773f4bf081bca73c9b9fe9ece";
	$mobile = trim($phone);
	$text="【东升物流】您的验证码是".$coding;
	$url = 'https://sms.yunpian.com/v2/sms/single_send.json';
	
	// 发送短信
	$data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
	$json_data = https_request($url,$data);

	$array = json_decode($json_data,true);
	echo '<pre>';print_r($array);
}
// cURL函数简单封装
function https_request($url, $data = null)
{
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, $url);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
 if (!empty($data)){
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($data));
 }
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 $output = curl_exec($curl);
 curl_close($curl);
 return $output;
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>

<center>
<form action="./sms.php" method="get">
手机: <input type="text" name="phone">
验证码: <input type="text" name="coding">
<input type="submit" name="sms" value="提交" /><br />
</form>
</center>
</body>
</html>
